<style type="text/css">
div.pagination {
	padding: 3px;
	margin: 3px;
}

div.pagination a {
font-family:Arial, Helvetica, sans-serif;
font-size:11px;
font-weight:normal;
	padding: 2px 5px 2px 5px;
	margin: 2px;
	border: 1px solid  #FF0000;
	
	text-decoration: none; /* no underline */
	color: #990000;   
}
div.pagination a:hover, div.pagination a:active {
	border: 1px solid #000099;

	color: #000;
}
div.pagination span.current {
	padding: 2px 5px 2px 5px;
	margin: 2px;
		border: 1px solid #990000;
		
		font-weight: bold;
		background-color: #990000;
		color: #FFF;
	}
	div.pagination span.disabled {
		padding: 2px 5px 2px 5px;
		margin: 2px;
		border: 1px solid #EEE;
	
		color: #DDD;
	}
	</style>
<?php
		$adjacents = 3;
		$lpm1 = $lastpage - 1;
		if ($pageCount == 1) {
		   echo "";
		} else {
		   echo " <a href='{$_SERVER['PHP_SELF']}?pageCount=1'>FIRST</a> ";
		   $prevpage = $pageCount-1;
		   echo " <a href='{$_SERVER['PHP_SELF']}?pageCount=$prevpage'>PREV</a> ";
		}
		/*for($i = 1; $i <= $lastpage; $i++)
						{ 
							if(($pageCount) == $i)
							{
								echo "<span class='current'>$i</span>";
							} 
							else 
							{
								echo "";
								echo "<a href='".$_SERVER['PHP_SELF']."?pageCount=$i' class='current'>$i</a>";
								echo "";
							}
						}*/
		//echo " ( Page $pageCount of $lastpage ) ";
		/**********************************/
		if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $pageCount)
					echo "<span class='current'>$counter</span>";
				else
					echo "<a href='{$_SERVER['PHP_SELF']}?pageCount=$counter'>$counter</a>";					
			}
		}
		elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
		{
			//close to beginning; only hide later pages
			if($pageCount < 1 + ($adjacents * 2))		
			{
				for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
				{
					if ($counter == $pageCount)
						echo "<span class='current'>$counter</span>";
					else
						echo "<a href='{$_SERVER['PHP_SELF']}?pageCount=$counter'>$counter</a>";					
				}
				echo  "...";
				echo  "<a href='{$_SERVER['PHP_SELF']}?pageCount=$lpm1'>$lpm1</a>";
				echo  "<a href='{$_SERVER['PHP_SELF']}?pageCount=$lastpage'>$lastpage</a>";		
			}
			//in middle; hide some front and some back
			elseif($lastpage - ($adjacents * 2) > $pageCount && $pageCount > ($adjacents * 2))
			{
				echo "<a href='{$_SERVER['PHP_SELF']}?pageCount=1'>1</a>";
				echo "<a href='{$_SERVER['PHP_SELF']}?pageCount=2'>2</a>";
				echo "...";
				for ($counter = $pageCount - $adjacents; $counter <= $pageCount + $adjacents; $counter++)
				{
					if ($counter == $pageCount)
						echo "<span class='current'>$counter</span>";
					else
						echo "<a href='{$_SERVER['PHP_SELF']}?pageCount=$counter'>$counter</a>";					
				}
				echo  "...";
				echo "<a href='{$_SERVER['PHP_SELF']}?pageCount=$lpm1'>$lpm1</a>";
				echo  "<a href='{$_SERVER['PHP_SELF']}?pageCount=$lastpage'>$lastpage</a>";		
			}
			//close to end; only hide early pages
			else
			{
				echo  "<a href='{$_SERVER['PHP_SELF']}?pageCount=1'>1</a>";
				echo "<a href='{$_SERVER['PHP_SELF']}?pageCount=2'>2</a>";
				echo "...";
				for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $pageCount)
						echo "<span class='current'>$counter</span>";
					else
						echo "<a href='{$_SERVER['PHP_SELF']}?pageCount=$counter'>$counter</a>";					
				}
			}
		}
		/**************************************/
		
		if ($pageCount == $lastpage) {
		   echo "";
		} else {
		   $nextpage = $pageCount+1;
		   echo " <a href='{$_SERVER['PHP_SELF']}?pageCount=$nextpage'>NEXT</a> ";
		   echo " <a href='{$_SERVER['PHP_SELF']}?pageCount=$lastpage'>LAST</a> ";
		}
?>